#include <stdlib.h>
#include <stdio.h>
#include <nds.h>

// common headers
#include "common.h"		// global

// local headers
#include "oggdecoder.h"

#include "main.h"

#define _VERSION_INT MAKE_VERSION(0, 0, 1, STATE_ALPHA, 1)
char _VERSION_STR[VERSION_STR_MAX_LEN+1];
char *_exts[]={ ".ogg", ".oga" };
sEL exts={
	.exts=_exts,
	.extnum=sizeof(_exts)/sizeof(*_exts)
};

// sound interface
sSInterface sSI = {
	.assign=assign,
	.getInfos=getInfos,
	.getTags=getTags,
	.setTags=setTags,
	.deassign=deassign,
	.play=play,            
	.pause=pause,
	.stop=stop,
	.seek=seek,
	.position2ms=position2ms,
	.ms2position=ms2position
};

int init() {
	std->sprintf(_VERSION_STR, VERSION_FORMAT, VERSION_ARGS(_VERSION_INT));	// make version str

std->iprintf("!");

// <-- test
/*
FILE *fd=std->fopen("/test.ogg", "rb");
std->iprintf("!");
if(!fd) return 1;
std->iprintf("!");
if(assign(fd)) return 1;
sSInfos i;
std->bzero(&i, sizeof(sSInfos));
std->iprintf("!");
if(getInfos(&i)) return 1;
play();
deassign();
std->fclose(fd);
*/
// -->

	return 0;
}

u32 query(u32 query) {
	switch(query) {
	case QUERY_NAME:		// library name
		return (u32)"libvorbis";
	case QUERY_VERSION_INT:	// library integer version
		return (u32)_VERSION_INT;
	case QUERY_VERSION_STR:	// library string version
		return (u32)_VERSION_STR;
	case QUERY_AUTHOR:		// library author
		return (u32)"SunDEV";
	case QUERY_FILEEXT:		// file extensions
		return (u32)&exts;
	case QUERY_ID:			// library identifier
		return ID_LIBRARY_SOUND;
	case QUERY_FSTRUCT:		// library functions structure
		return (u32)&sSI;
	default:
		return 0;
	}
}

void deinit() {
}

void _ludo_exit(int i) {
	std->iprintf("exit() !!!\n");
	while(1);
}
int _ludo_errno=0;

sKeysInstance _keys;

